layui.define(['table', 'form', 'admin'], function (exports) {
    var $ = layui.$
        , table = layui.table
        , form = layui.form
        , admin = layui.admin;

    table.render({
        elem: '#LAY-white-manage'
        , url: '/admin/white_ip/lists'
        , cols: [[
            {field: "id", width: 100, title: "ID", fixed: "left"},
            {field: 'ip', width: 180, title: '白名单IP',},
            {field: 'remark', width: 180, title: '备注',},
            {field: 'status', width: 180, title: '状态',},
            {field: 'admin_name', width: 180, title: '添加人',},
            {field: 'created_at', title: '创建时间',},
            {field: 'updated_at', title: '操作时间',},
            {title: '操作', width: 300, align: 'center', fixed: 'right', toolbar: '#table-white-list'}
        ]]
        , page: true
        , limit: 50
        , height: 'full-140'
        , text: '对不起，加载出现异常！'
        , even: true
    });
    table.on("tool(LAY-white-manage)", function (obj) {
        if (obj.event === "set_status") {
            layer.confirm("确定生效/失效IP？", function (index) {
                admin.req({
                    url: "/admin/white_ip/set_status",
                    data: { id: obj.data.id },
                    success(res) {
                        if (res.code == 0) {

                            table.reload("LAY-white-manage");
                            layer.msg(res.msg, { icon: 1 });
                        } else {
                            layer.msg(res.msg, { icon: 5 });
                        }
                    },
                });
            });

        }
    });

    exports('white_ip', {})
});
